/*
	ctlmodule.v
	Add/Sub control module for ucordic module
	
	This project and file(s) are released under GNU GPL v3.
	Please find license file from root directory.
	Meng Sun (c) 2013 <leon.meng.sun@gmail.com>
*/

module ctlmodule (ApproxMode, CoordMode, MSBY, MSBZ, ZRY, ModeX, ModeY, ModeZ);

input ApproxMode;
input [1:0] CoordMode;
input MSBY, MSBZ, ZRY;
output ModeX, ModeY, ModeZ;

wire ApproxMode;
wire [1:0] CoordMode;
wire MSBY, MSBZ, ZRY;
reg ModeX, ModeY, ModeZ;

always @ (ApproxMode or CoordMode or MSBY or MSBZ or ZRY)
begin
  if (((ApproxMode == 0) && (MSBY == 0)) || ((ApproxMode == 0) && (ZRY == 1)) || ((ApproxMode == 1) && (MSBZ == 1)))
  begin
     case (CoordMode)
     2'b01:
        ModeX = 0;
     2'b00:
        ModeX = 0;
     2'b11:
        ModeX = 1;
     default:
        ModeX = 0;
     endcase
     ModeY = 1;
     ModeZ = 0;
  end
  else
  begin
     case (CoordMode)
     2'b01:
        ModeX = 1;
     2'b00:
        ModeX = 0;
     2'b11:
        ModeX = 0;
     default:
        ModeX = 0;
     endcase
     ModeY = 0;
     ModeZ = 1;
  end
end

endmodule